package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.net.RequestTip;

import io.reactivex.rxjava3.functions.Consumer;

/**
 * CREATE BY zlzxm ON 2021/5/11
 */
public class BaseViewModel extends ViewModel {

    protected ThrowableCallback throwableCallback = new ThrowableCallback();

    protected MutableLiveData<String> liveErrorToast = new MutableLiveData<>();

    protected MutableLiveData<String> liveWarningToast = new MutableLiveData<>();

    protected MutableLiveData<String> liveSucceedToast = new MutableLiveData<>();

    protected MutableLiveData<Boolean> liveNeedLogin = new MutableLiveData<>();

    public MutableLiveData<String> getLiveErrorToast() {
        return liveErrorToast;
    }

    public MutableLiveData<String> getLiveWarningToast() {
        return liveWarningToast;
    }

    public MutableLiveData<String> getLiveSucceedToast() {
        return liveSucceedToast;
    }

    public MutableLiveData<Boolean> getLiveNeedLogin() {
        return liveNeedLogin;
    }



    public class ThrowableCallback implements Consumer<Throwable> {

        @Override
        public void accept(Throwable throwable) throws Throwable {
            throwable.printStackTrace();
            liveErrorToast.setValue(RequestTip.REQUEST_ERROR);
        }
    }

}
